﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Mechanics.GameEventMechanics {
    import Engine.Managers.*;
    import flash.display.*;
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import flash.utils.*;
    import Classes.*;
    import Display.*;
    import Modules.zoo.ui.*;
    import Display.FriendRewardsUI.*;

    public class DialogGenerationMechanic implements IDialogGenerationMechanic {

        private static var dialogs:Array = [ZooDialog, FriendRewardsDialog, ZooUnlockDialog];

        protected var m_owner:MechanicMapResource;
        protected var m_config:MechanicConfigData;

        public function hasOverrideForGameAction(_arg1:String):Boolean{
            return (this.canPopDialog());
        }
        public function executeOverrideForGameEvent(_arg1:String, _arg2:Array=null):MechanicActionResult{
            var _local3:DisplayObject;
            var _local4:Boolean;
            var _local5:Boolean;
            if (this.canPopDialog()){
                _local3 = this.instantiateDialog();
                _local4 = true;
                if (this.m_config.params["popImmediately"] == "true"){
                    _local4 = false;
                };
                UI.displayPopup(_local3, _local4, this.m_config.type, true);
                this.trackDialog();
                _local5 = ((this.m_config.params["proceed"] == "false")) ? false : true;
                return (new MechanicActionResult(true, _local5, false));
            };
            return (new MechanicActionResult(false, true, false));
        }
        public function instantiateDialog():DisplayObject{
            var _local2:DisplayObject;
            var _local1:Class = (getDefinitionByName(this.m_config.params["dialogToPop"]) as Class);
            var _local3:Object = this.getDataForDialog();
            if (_local3){
                _local2 = new _local1(this.m_owner, _local3);
            } else {
                _local2 = new _local1(this.m_owner);
            };
            return (_local2);
        }
        public function trackDialog():void{
            if (this.m_config.params["phylum"]){
                StatsManager.sample(100, this.m_config.params["counter"], this.m_config.params["kingdom"], this.m_config.params["phylum"]);
            } else {
                if (this.m_config.params["kingdom"]){
                    StatsManager.sample(100, this.m_config.params["counter"], this.m_config.params["kingdom"]);
                } else {
                    if (this.m_config.params["counter"]){
                        StatsManager.sample(100, this.m_config.params["counter"]);
                    };
                };
            };
        }
        public function canPopDialog():Boolean{
            if ((this.m_owner is HarvestableResource)){
                if ((this.m_owner as HarvestableResource).isHarvestable()){
                    return (false);
                };
            };
            return (true);
        }
        public function initialize(_arg1:IMechanicUser, _arg2:MechanicConfigData):void{
            this.m_owner = (_arg1 as MechanicMapResource);
            this.m_config = _arg2;
        }
        public function isVisitEnabled():Boolean{
            return (false);
        }
        public function getDataForDialog():Object{
            var _local2:Object;
            var _local1:String = this.m_config.params["dataSourceType"];
            if (((_local1) && ((_local1.length > 0)))){
                _local2 = this.m_owner.getDataForMechanic(_local1);
                return (_local2);
            };
            return (null);
        }

    }
}//package Mechanics.GameEventMechanics 
